#pragma once
#include "res.h"

constexpr float 棋子大小 = 60; // 直径
constexpr float 棋子半径 = 棋子大小 * 0.5f;

// 颜色定义
constexpr Color 红棋颜色 = createColor(255, 0, 0, 255);
constexpr Color 黑棋颜色 = createColor(0, 0, 0, 255);
constexpr Color 棋子颜色 = createColor(255, 205, 144, 255);

enum class ChessManType
{
	红车, 红马, 红炮, 红兵, 红相, 红仕, 红帅,
	黑车, 黑马, 黑炮, 黑卒, 黑象, 黑士, 黑将,
	NUM_MAX, 空 = -1,
};

constexpr std::array<std::string_view, 14> CHESS_MAN_NAME = {
	"車", "馬", "炮", "兵", "相", "仕", "帥",
	"車", "馬", "炮", "卒", "象", "士", "將",
};

// 红方返回true
constexpr bool GetManSide(ChessManType type)
{
	return type < ChessManType::黑车;
}
constexpr std::string_view GetChessName(ChessManType type)
{
	if (type == ChessManType::空)
		return "null";
	return CHESS_MAN_NAME[(size_t)type];
}

class ChessMan
{
public:
	ChessMan() :
		_type{ ChessManType::空 }
	{
		_txt = g_Res->GetTextMan(true);
		_txt->SetOrder(ORDER_CHESS_MAN);
	}
	ChessMan(ChessManType type) :
		_type{ type }
	{
		_sprBg = g_factory->CreateSprite("man");
		_sprBg->SetOrder(ORDER_CHESS_MAN);
		_txt = g_Res->GetTextMan(GetManSide(_type));
		_txt->SetOrder(ORDER_CHESS_MAN);
		_txt->SetString(GetChessName(type));
	}
	void Render()
	{
		if(_sprBg)
			_sprBg->Render();
		_txt->Render();
	}
	void SetParent(Coor* parent)
	{
		if (_sprBg)
			_sprBg->SetCoor(parent);
		_txt->GetCoor()->SetParent(parent);
	}
	void SetXy(const PointU& xy);
private:
	ChessManType _type;
	gcSprite _sprBg;
	gcText _txt;
	PointU _xy;
};